/**
 * @file 订单标签配置
 * @author liuying
 * @date 2021-07-30 15:24:11
 */

layui.define(['element', 'layer', 'form', 'table', 'zmnOmsSelect', 'zmnSelect', 'laytpl', 'laydate', '$http'], function (exports) {
    let $ = layui.$;
    let form = layui.form;
    let $http = layui.$http;
    let layer = layui.layer;
    let laydate = layui.laydate;
    let zmnOmsSelect = layui.zmnOmsSelect;
    let zmnSelect = layui.zmnSelect;
    var table = layui.table;

    let CONF_BASE_URL = OMS_BASE_URL + '/tips/config';

    /**
     * 渲染表格
     * @param {object} params 查询参数
     * @returns {object}
     */
    function renderTable() {
        table.render({
            elem: '#tips-conf-table',
            url: CONF_BASE_URL + '/ajax/list.action',
            toolbar: '#security-tips',
            where: getSearchParams(),
            defaultToolbar: ['filter', 'print'],
            page: true,
            cols: [[
                {field: 'servCategName', align: 'center', title: '服务分类名称'},
                {field: 'categOneName', align: 'center', title: '前台一级分类'},
                {field: 'categName', align: 'center', title: '前台二级分类'},
                {fixed: 'right', align: 'center', title: '操作', templet: '#securityTips', width: 100},
            ]],
            request: {
                pageName: 'pageIndex', // 页码
                limitName: 'pageSize' // 条数限制
            },
            response: {
                statusCode: 200 // 重新规定成功的状态码为 200，table 组件默认为 0
            },
            parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
                var count = res.data ? res.data.count : 0;
                $('.layui-this').find('.count').text('（共 ' + count + ' 条）');
                return {
                    "code": res.status,
                    "msg": res.message,
                    "count": res.data ? (res.data.count > 10000 ? 10000 : res.data.count) : 0, //解析数据长度
                    "data": res.data ? res.data.data : [] //解析数据列表
                };
            },
        });
    }

    // 监听行工具事件
    table.on('tool(tips-conf-table)', function (obj) {
        console.log("obj：", obj)
        let data = obj.data;
        if (obj.event === 'tips') {
            let url = CONF_BASE_URL + '/detail.action?servCategId=' + data.servCategId + '&categOneId=' + data.categOneId + '&categId=' + data.categId;
            zmnLayUtil.openIframeCustom(layer, url, {title: "安全提示", shade: 0.8, area: ["760px", "540px"]});
        }
    });


    // 监听重置按钮点击
    form.on('submit(submit-reset)', function (obj) {
        $('select').val('');
        $('input').val('');
        table.reload("tips-conf-table", {
            where: getSearchParams(obj.field),
            page: {
                curr: 1 //重新从第 1 页开始
            }
        });
        return false;
    });

    function getSearchParams(field) {
        let params = {};
        if (field) {
            // 拷贝非空字段
            Object.keys(field).filter((key) => {
                params[key] = field[key];
            });
        }
        return params;
    }

    // 查询
    form.on('submit(submit-search)', function (obj) {
        table.reload("tips-conf-table", {
            where: getSearchParams(obj.field),
            page: {
                curr: 1 //重新从第 1 页开始
            }
        });
        return false;
    });

    zmnSelect.selectlEcProdCategories({
        servCategSelectId: 'servCategId',
        ecCategOneSelectId: 'categOneId',
        ecCategTwoSelectId: 'categId',
    }, {
        servCategSelectId: {
            selectedValues: "",
            remote: {
                limitPermit: 10,
            },
            events: {
                changed(values) {
                    console.log("==========ecServCategId3=========");
                    console.log("已选中的值:" + values);
                }
            }
        },
        ecCategOneSelectId: {
            selectedValues: "",
            remote: {
                limitPermit: 10,
            },
            events: {
                changed(values) {
                    console.log("==========ecCategOneId3=========");
                    console.log("已选中的值:" + values);
                }
            }
        },
        ecCategTwoSelectId: {
            selectedValues: "",
            remote: {
                limitPermit: 10,
            },
            events: {
                changed(values) {
                    console.log("==========ecCategTwoId3=========");
                    console.log("已选中的值:" + values);
                }
            }
        }
    });

    renderTable();
    exports('oms_conf_tips_list');
});
